layui.use(['jquery','form','element'], function(){
    var $ = layui.jquery;
    var form = layui.form();
    var element = layui.element();
    $.ajax({
        type: "GET",
        url: "/admin/project/getProject",
        dataType: "json",
        success: function (res) {
            var ops = '<option value="">--请选择--</option>';
            for (var project of res.data) {
                ops += '<option value="' + project.projectcode + '">' + project.projectname + '</option>';
            }
            $('#project').html(ops);
            form.render();
        }
    });
    form.on('select(Pfilter)',function() {
        var p = $('#project').val();
        alert(p)
        $.ajax({
            type: "GET",
            url: "/admin/building/getBuildingByPid",
            data: {"pid": p},
            dataType: "json",
            success: function (res1) {
                var ops1 = '<option value="">--请选择--</option>';
                for (var building of res1.data) {
                    ops1 += '<option value="' + building.bCodes + '">' + building.bName + '</option>';
                }
                $('#building').html(ops1);
                form.render();
            }
        })
    })
    form.on('select(Bfilter)',function() {
        var p = $('#building').val();
        alert(p)
        $.ajax({
            type: "GET",
            url: "/admin/Suite/getSuiteByBid",
            data: {"bid": p},
            dataType: "json",
            success: function (res2) {
                var ops2 = '<option value="">--请选择--</option>';
                for (var suite of res2.data) {
                    ops2 += '<option value="' + suite.code + '">' + suite.code + '</option>';
                }
                $('#suite').html(ops2);
                form.render();
            }
        })
    })
    form.on('select(Sfilter)',function() {
        var p = $('#suite').val();
        alert(p)
        $.ajax({
            type: "GET",
            url: "/admin/Room/getRoomBySid",
            data: {"sid": p},
            dataType: "json",
            success: function (res3) {
                var ops3 = '<option value="">--请选择--</option>';
                for (var room of res3.data) {
                    ops3 += '<option value="' + room.code + '">' + room.name + '</option>';
                }
                $('#room').html(ops3);
                form.render();
            }
        })
    })
    form.on('select(Rfilter)',function() {
        var p = $('#room').val();
        alert(p)
        $.ajax({
            type: "GET",
            url: "/admin/Bunk/getBunkByRid",
            data: {"rid": p},
            dataType: "json",
            success: function (res4) {
                var ops4 = '<option value="">--请选择--</option>';
                for (var bunk of res4.data) {
                    ops4 += '<option value="' + bunk.code + '">' + bunk.code + '</option>';
                }
                $('#bunk').html(ops4);
                form.render();

            }
        })
    })
});